home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / SCREEN / CURSES01 / minix / c / prntscan < prev    next >
Text File  |  1991-05-05  |  7KB  |  192 lines

  1. /****************************************************************/
  2. /* Printw() and scanw() routines of the PCcurses package    */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /* 1.0:    Release:                    870515    */
  12. /****************************************************************/
  13. /* Modified to run under the MINIX operating system by Don Cope */
  14. /* These changes are also released into the public domain.      */
  15. /*                             900906  */
  16. /****************************************************************/
  17.  
  18. #include <curses.h>
  19. #include "curspriv.h"
  20.  
  21. static    int    pblen();        /* gets length of bufer */
  22.  
  23. /****************************************************************/
  24. /*             IMPLEMENTATION NOTE            */
  25. /* These routines make a local copy of their parameter stack,    */
  26. /* assuming at most 5 'double' arguments were passed (== 40    */
  27. /* bytes == 20 int's == 10 long's == 10-20 pointers {depending    */
  28. /* on memorymodel}, etc). This means the invokation of the    */
  29. /* routines themself require at least 80 bytes of stack just    */
  30. /* for the parameters, and the sprintf() and sscanf() functions    */
  31. /* will require more. Therefore, this module should be compiled    */
  32. /* with stack checking on to avoid stack overflow errors.    */
  33. /****************************************************************/
  34.  
  35. static    char    printscanbuf[513];    /* buffer used during I/O */
  36.  
  37. /****************************************************************/
  38. /* Wprintw(win,fmt,args) does a printf() in window 'win'.    */
  39. /****************************************************************/
  40.  
  41. int    wprintw(win,fmt,A1,A2,A3,A4,A5)
  42.   WINDOW    *win;
  43.   char        *fmt;
  44.   double     A1,A2,A3,A4,A5;
  45.   {
  46.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  47.   if (waddstr(win,printscanbuf) == ERR)
  48.     return(ERR);
  49.   return(pblen());
  50.   } /* wprintw */
  51.  
  52. /****************************************************************/
  53. /* Printw(fmt,args) does a printf() in stdscr.            */
  54. /****************************************************************/
  55.  
  56. int    printw(fmt,A1,A2,A3,A4,A5)
  57.   char        *fmt;
  58.   double     A1,A2,A3,A4,A5;
  59.   {
  60.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  61.   if(waddstr(stdscr,printscanbuf) == ERR)
  62.     return(ERR);
  63.   return(pblen());
  64.   } /* printw */
  65.  
  66. /****************************************************************/
  67. /* Mvprintw(fmt,args) moves the stdscr cursor to a new posi-    */
  68. /* tion, then does a printf() in stdscr.            */
  69. /****************************************************************/
  70.  
  71. int    mvprintw(y,x,fmt,A1,A2,A3,A4,A5)
  72.   int         y;
  73.   int         x;
  74.   char        *fmt;
  75.   double     A1,A2,A3,A4,A5;
  76.   {
  77.   if (wmove(stdscr,y,x) == ERR)
  78.     return(ERR);
  79.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  80.   if(waddstr(stdscr,printscanbuf) == ERR)
  81.     return(ERR);
  82.   return(pblen());
  83.   } /* mvprintw */
  84.  
  85. /****************************************************************/
  86. /* Mvwprintw(win,fmt,args) moves the window 'win's cursor to    */
  87. /* a new position, then does a printf() in window 'win'.    */
  88. /****************************************************************/
  89.  
  90. int    mvwprintw(win,y,x,fmt,A1,A2,A3,A4,A5)
  91.   WINDOW    *win;
  92.   int         y;
  93.   int         x;
  94.   char        *fmt;
  95.   double     A1,A2,A3,A4,A5;
  96.   {
  97.   if (wmove(win,y,x) == ERR)
  98.     return(ERR);
  99.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  100.   if(waddstr(win,printscanbuf) == ERR)
  101.     return(ERR);
  102.   return(pblen());
  103.   } /* mvwprintw */
  104.  
  105. /****************************************************************/
  106. /* Wscanw(win,fmt,args) gets a string via window 'win', then    */
  107. /* scans the string using format 'fmt' to extract the values    */
  108. /* and put them in the variables pointed to the arguments.    */
  109. /****************************************************************/
  110.  
  111. int wscanw(win,fmt,A1,A2,A3,A4,A5)
  112.   WINDOW    *win;
  113.   char        *fmt;
  114.   double     A1,A2,A3,A4,A5;        /* really pointers */
  115.   {
  116.   wrefresh(win);                /* set cursor */
  117.   if (wgetstr(win,printscanbuf) == ERR)        /* get string */
  118.     return(ERR);
  119.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  120.   } /* wscanw */
  121.  
  122. /****************************************************************/
  123. /* Scanw(fmt,args) gets a string via stdscr, then scans the    */
  124. /* string using format 'fmt' to extract the values and put them    */
  125. /* in the variables pointed to the arguments.            */
  126. /****************************************************************/
  127.  
  128. int scanw(fmt,A1,A2,A3,A4,A5)
  129.   char        *fmt;
  130.   double     A1,A2,A3,A4,A5;        /* really pointers */
  131.   {
  132.   wrefresh(stdscr);                /* set cursor */
  133.   if (wgetstr(stdscr,printscanbuf) == ERR)    /* get string */
  134.     return(ERR);
  135.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  136.   } /* scanw */
  137.  
  138. /****************************************************************/
  139. /* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi-    */
  140. /* tion, then gets a string via stdscr and scans the string    */
  141. /* using format 'fmt' to extract the values and put them in the    */
  142. /* variables pointed to the arguments.                */
  143. /****************************************************************/
  144.  
  145. int mvscanw(y,x,fmt,A1,A2,A3,A4,A5)
  146.   int         y;
  147.   int         x;
  148.   char        *fmt;
  149.   double     A1,A2,A3,A4,A5;        /* really pointers */
  150.   {
  151.   if (wmove(stdscr,y,x) == ERR)
  152.     return(ERR);
  153.   wrefresh(stdscr);                /* set cursor */
  154.   if (wgetstr(stdscr,printscanbuf) == ERR)    /* get string */
  155.     return(ERR);
  156.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  157.   } /* mvscanw */
  158.  
  159. /****************************************************************/
  160. /* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a    */
  161. /* new position, then gets a string via 'win' and scans the    */
  162. /* string using format 'fmt' to extract the values and put them    */
  163. /* in the variables pointed to the arguments.            */
  164. /****************************************************************/
  165.  
  166. int mvwscanw(win,y,x,fmt,A1,A2,A3,A4,A5)
  167.   WINDOW    *win;
  168.   int         y;
  169.   int         x;
  170.   char        *fmt;
  171.   double     A1,A2,A3,A4,A5;        /* really pointers */
  172.   {
  173.   if (wmove(win,y,x) == ERR)
  174.     return(ERR);
  175.   wrefresh(win);                /* set cursor */
  176.   if (wgetstr(win,printscanbuf) == ERR)        /* get string */
  177.     return(ERR);
  178.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  179.   } /* mvwscanw */
  180.  
  181. /****************************************************************/
  182. /* Pblen() returns the length of the string in printscanbuf.    */
  183. /****************************************************************/
  184.  
  185. static    int pblen()
  186.   {
  187.   char *p = printscanbuf;
  188.   
  189.   while(*p++);
  190.   return(p-printscanbuf-1);
  191.   } /* plben */
  192.